package mqtt

import (
	"encoding/json"
	"io"
	"os"
)

type MqttProtocol struct {
	Topic       string `json:"topic"`
	Payload     string `json:"payload"`
	Description string `json:"description"`
}

func GetProtocolDataFromJson() []MqttProtocol {

	file, _ := os.OpenFile("./mqtt_protocol.json", os.O_RDONLY, 0666)
	defer func(f *os.File) {
		err := f.Close()
		if err != nil {
			panic(err)
		}
	}(file)
	var result struct {
		Data []MqttProtocol `json:"data"`
	}
	byteValue, _ := io.ReadAll(file)
	err := json.Unmarshal(byteValue, &result)
	if err != nil {
		println("解析JSON数据出错:", err)
	}
	return result.Data
}
